package com.yiwei.zhh.view;

import android.app.*;
import android.content.Context;
import android.content.res.Configuration;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.zhh.R;
import com.yiwei.zhh.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/3/16 0016.
 */
public class SelectCodeTypeDialog extends android.app.Dialog {


    @BindView(R.id.btn_alipay)
    TextView btnAlipay;
    @BindView(R.id.btn_wechat)
    SuperButton btnWechat;
    @BindView(R.id.btn_cancel)
    SuperButton btnCancel;
    private Context context;


    public SelectCodeTypeDialog(Context context) {
        super(context, R.style.mydialog);
        this.context = context;
        init();
    }

    public SelectCodeTypeDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public SelectCodeTypeDialog setOnSelect(OnSureListener listener) {
        selectListener = listener;
        return this;
    }

    @Override
    public void show() {
        super.show();
    }

    @OnClick({R.id.btn_alipay, R.id.btn_wechat, R.id.btn_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_alipay:
                if(selectListener!=null){
                    selectListener.onAlipay();
                }
                dismiss();
                break;
            case R.id.btn_wechat:
                if(selectListener!=null){
                    selectListener.onWechat();
                }
                dismiss();
                break;
            case R.id.btn_cancel:
                dismiss();
                break;
        }
    }


    public interface OnSureListener {
        void onAlipay();

        void onWechat();
    }

    private OnSureListener selectListener;

    private void init() {
        Window window = this.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.setWindowAnimations(R.style.mydialog_animation);
        setContentView(R.layout.dialog_select_code_type);
        ButterKnife.bind(this);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = Util.getDisplayMetrics(context).heightPixels / 10 * 8;
        } else {
            lp.width = Util.getDisplayMetrics(context).widthPixels / 10 * 8;
        }
        window.setAttributes(lp);
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        this.setCanceledOnTouchOutside(false);


    }


}
